package com.datastructure.test.numberofpalindromicsubstrings;

public class NumberOfPalindromicSubstrings {

    public static void main(String[] args) {
        NumberOfPalindromicSubstrings numberOfPalindromicSubstrings = new NumberOfPalindromicSubstrings();
        int nowcoder = numberOfPalindromicSubstrings.Substrings("nowcoder");
        System.out.println(nowcoder);
    }

    public int Substrings (String str) {
        // write code here
        int subStr = 0;
        StringBuilder stringBuilder ;
        for ( int i = 0 ; i < str.length() ; i++) {
            for (int j = (i + 1); j <= str.length(); j++) {
                stringBuilder = new StringBuilder(str.substring(i, j));
                if (stringBuilder.toString().equals(stringBuilder.reverse().toString()))
                    subStr++;
            }
        }
        return subStr;
    }
}
